package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueLiaisonDao;
import com.prs.crm.domain.crm.Liaison;
import com.prs.crm.domain.doc.IssueLiaison;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.crm.LiaisonService;
import com.prs.crm.service.doc.IssueLiaisonService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class IssueLiaisonServiceImpl extends BaseServiceImpl<IssueLiaison,IssueLiaisonDao> implements IssueLiaisonService{
	private PersonService personService;
	private LiaisonService liaisonService;


	@Override
	public void submitIssueLiaison(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> receivePerson = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Liaison> liaisons = this.getLiaisonService().getLiaisonByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		for(Liaison liaison:liaisons) {
			for(Person person : receivePerson) {
				IssueLiaison issue = new IssueLiaison();
				issue.setLiaison(liaison);
				issue.setRecorder(person);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				this.getDao().save(issue);
			}
		}
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}
	
	public LiaisonService getLiaisonService() {
		return liaisonService;
	}

	public void setLiaisonService(LiaisonService liaisonService) {
		this.liaisonService = liaisonService;
	}
	@Override
	public Collection<IssueLiaison> getValidIssueLiaison(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueLiaison(person);
	}

}
